<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <link rel="shortcut icon" href="../img/favicon.ico" />
    <title>About - My docs</title>
    <link rel="stylesheet" href="../css/theme.css" />
    <link rel="stylesheet" href="../css/theme_extra.css" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" />
    
      <script>
        // Current page data
        var mkdocs_page_name = "About";
        var mkdocs_page_input_path = "README2.md";
        var mkdocs_page_url = null;
      </script>
    
    <script src="../js/jquery-3.6.0.min.js" defer></script>
    <!--[if lt IE 9]>
      <script src="../js/html5shiv.min.js"></script>
    <![endif]-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
      <script>hljs.initHighlightingOnLoad();</script> 
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
          <a href=".." class="icon icon-home"> My docs
        </a><div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
                <li class="toctree-l1"><a class="reference internal" href="..">Home</a>
                </li>
              </ul>
              <ul class="current">
                <li class="toctree-l1 current"><a class="reference internal current" href="./">About</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#_2">项目结构</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_3">配置文件说明</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_4">运行环境配置</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_5">创建测试用例(举例)</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_6">执行用例</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_7">默认屏幕分辨率</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_8">辅助工具</a>
    </li>
    </ul>
                </li>
              </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      <nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="..">My docs</a>
        
      </nav>
      <div class="wy-nav-content">
        <div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href=".." class="icon icon-home" alt="Docs"></a> &raquo;</li><li>About</li>
    <li class="wy-breadcrumbs-aside">
    </li>
  </ul>
  <hr/>
</div>

          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
            <div class="section" itemprop="articleBody">
              
                <h2 id="_1">简介</h2>
<h3 id="_2">项目结构</h3>
<pre><code>Automation_AV_Direct_UI
├─data
│  └─pics                 页面参照基础图片
├─file_log                日志存放目录
├─file_cp                 
│  └─pics                 用例图片临时存放目录
├─locators                用例页面元素定位
├─notebooks             
├─pages                   用例页面业务逻辑
├─report                  用例测试报告存放目录
│  └─png                  用例失败截图
├─scripts            
├─xxtest                    用例具体存放目录
├─utils                   公共函数存放目录
│  ├─aws_util.py                 
│  ├─email_util.py                 处理邮件函数
│  ├─file_util.py                  处理文件函数
│  ├─getCoord_util.py                 
│  ├─ocr_util.py                   图片/文字识别相关函数
│  ├─pywinautoUtil.py              pywinauto相关函数
│  ├─RollingReturnUtil.py          
│  └─utils.py                      处理页面控件函数
├─.gitignore                   
├─conftest.py                   
├─main.py                          主入口
├─pytest.ini                   
├─README.md             
└─requirements.txt            
</code></pre>
<h3 id="_3">配置文件说明</h3>
<h3 id="_4">运行环境配置</h3>
<ol>
<li>下载安装<a href="https://github.com/microsoft/WinAppDriver">Winappdriver</a>
   ，版本选择V1.2.1</li>
<li>下载安装<a href="https://python.org/downloads/windows/">Python3</a>
   ，版本建议选择V3.9.9</li>
<li>开发集成工具<a href="https://www.jetbrains.com/pycharm/download/#section=windows">Pycharm</a></li>
<li>安装依赖模块: pip3 install -r requirements.txt</li>
</ol>
<h3 id="_5">创建测试用例(举例)</h3>
<p>以测试登录Direct为例<br />
1.在<strong><em>locators</em></strong>目录下Login_Locators.py，定义所需要控件元素的定位</p>
<pre><code>from appium.webdriver.common.mobileby import MobileBy

class LoginPageLocators(object):
    USERNAME = (MobileBy.ACCESSIBILITY_ID, 'emailInput')
    PASSWORD = (MobileBy.ACCESSIBILITY_ID, 'passwordInput')
    SIGNIN = (MobileBy.NAME, 'Sign In')
    SIGN_IN_TEXT = (MobileBy.NAME, 'Sign In to Direct')
</code></pre>
<p>2.在<strong><em>pages</em></strong>目录下创建login_page.py，定义登录相关业务</p>
<pre><code>from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium.webdriver.common.mobileby import MobileBy
from appium import webdriver
from locators.Login_Locators import LoginPageLocators
import pyautogui as auto

def start_direct():
    desired_caps = {'app': r&quot;C:\Program Files (x86)\Morningstar\Direct\MStarAWD.exe&quot;}
    direct_driver = webdriver.Remote(command_executor='http://127.0.0.1:4723',
                                     desired_capabilities=desired_caps)
    login_direct(direct_driver, &quot;bttf.pdop.autotester01@morningstar.com&quot;)
    exp_ele = direct_driver.find_element(MobileBy.XPATH, &quot;//Tab[@Name='XTPDockingPaneTabbedContainer']&quot;)
    return exp_ele


def login_direct(direct_driver, username):
    password = &quot;BttfTester2020&quot;
    WebDriverWait(direct_driver, 10).until(EC.visibility_of_element_located(LoginPageLocators.SIGN_IN_TEXT)).click()
    auto.scroll(-500)
    ele_username = WebDriverWait(direct_driver, 10).until(EC.visibility_of_element_located(LoginPageLocators.USERNAME))
    ele_username.sendkeys(username)
    ele_password = WebDriverWait(direct_driver, 10).until(EC.visibility_of_element_located(LoginPageLocators.USERNAME))
    ele_password.sendkeys(password)
    ele_sign = WebDriverWait(direct_driver, 10).until(EC.visibility_of_element_located(LoginPageLocators.SIGNIN))
    ele_sign.click()
    handles = direct_driver.window_handles
    direct_driver.switch_to.window(handles[0])
</code></pre>
<p>3.在<strong><em>xxtest</em></strong>目录下,创建test_login_direct.py，定义测试用例</p>
<pre><code>from login_page import *

def test_login_direct():
   res_test = start_direct()
   assert exp_ele is not None
</code></pre>
<h3 id="_6">执行用例</h3>
<ol>
<li>本地运行Winappdirver.exe</li>
<li>运行所有用例: pytest</li>
<li>运行单个用例: pytest  xxtest\test_xxx.py</li>
<li>运行用例并生成测试报告: pytest --html=xxx.html</li>
<li>运行用例并将测试报告以邮件的方式发送：python main.py</li>
</ol>
<h3 id="_7">默认屏幕分辨率</h3>
<p>1920*1080</p>
<h3 id="_8">辅助工具</h3>
<ol>
<li>inspect.exe</li>
<li><a href="https://github.com/microsoft/WinAppDriver/tree/master/Tools/UIRecorder">UIRecorder.sln</a>     </li>
</ol>
              
            </div>
          </div><footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
        <a href=".." class="btn btn-neutral float-left" title="Home"><span class="icon icon-circle-arrow-left"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
          
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="Versions">
  <span class="rst-current-version" data-toggle="rst-current-version">
    
    
      <span><a href=".." style="color: #fcfcfc">&laquo; Previous</a></span>
    
    
  </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme_extra.js" defer></script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
